SciChart WPF 2D Charts > Axis APIs > Discontinuous DateTime Axis and Double-Scale Axis
Discontinuous DateTime Axis and Double-Scale Axis

The DiscontinuousDateTimeAxis is a Value-Axis suitable for the XAxis when the data on the XAxis is a DateTime. It is not suitable for YAxis or other data-types. 

This axis differs from the DateTimeAxis in that it allows you to skip periodic dates/times, or time ranges from the chart. For example:

  • A factory or process schedule where you want to exclude Weekends
  • A stock chart where you want to exclude overnight sessions where the exchange is closed.

Declaring a DiscontinuousDateTimeAxis

Use the following code to decalare a DiscontinuousDateTimeAxis.

<s:SciChartSurface.XAxis>
   <s:DiscontinuousDateTimeAxis DrawMajorBands="True" GrowBy="0.0, 0.1" />
</s:SciChartSurface.XAxis>
var sciChartSurface = new SciChartSurface();
 
var xAxis = new DiscontinuousDateTimeAxis
{
    Calendar = new DefaultDiscontinuousDateTimeCalendar(),
    GrowBy = new DoubleRange(0.0, 0.1),
    AxisAlignment = AxisAlignment.Bottom,
    AxisTitle = "Time",
    Calendar = new DefaultDiscontinuousDateTimeCalendar(),
};
 
sciChartSurface.XAxis = xAxis;
NOTE: if you don’t set the Calender property it will use DefaultDiscontinuousDateTimeCalendar and will behave like DateTimeAxis.

Calendars

IDiscontinuousDateTimeCalendar is a base interface for calendars. DiscontinuousDateTimeCalendarBase is a base abstract class that provides basic functionality for calendars (checking if value is in a gap, getting time in ticks between dates taking gaps into account etc.).

For creating your custom calendars, you should inherit it from DiscontinuousDateTimeCalendarBase and change the following collections:

  • SkipDateTimeRange – skips time ranges within a day.
  • SkipDaysInWeek – skips days of week.
  • SkipDateTimeRange – skips particular dates.

In our examples, there are two implemented calendars: NYSECalendar and LSECalendar. These are defined as follows:

Example DiscontinuousDateTimeAxis Calendars
Copy Code
/// <summary>
/// Example of how to make a Discontinuous DateTime Calender for the New York Stock Exchange
///
/// If you wish to extend this, ensure that public holidays are set for the year(s) which you wish to show data
/// e.g. https://www.redcort.com/us-federal-bank-holidays/
/// </summary>
public class NYSECalendar : DiscontinuousDateTimeCalendarBase
{
    public NYSECalendar()
    {
        // For intraday data, you can add a skip range like this.
        // For daily data, skip ranges will cause the Daily OHLC bars with timestamp at 0:00:00 to be skipped
        //SkipDayTimeRange.Add(new TimeSpanRange(new TimeSpan(0, 0, 0), new TimeSpan(9, 30, 0))); // NYSE is open at 9:30 am EST
        //SkipDayTimeRange.Add(new TimeSpanRange(new TimeSpan(16, 0, 0), new TimeSpan(24, 0, 0))); // NYSE is closed at 16:00 pm EST
        // NYSE is closed on weekends
        SkipDaysInWeek.Add(DayOfWeek.Saturday);
        SkipDaysInWeek.Add(DayOfWeek.Sunday);
        SkipDates.Add(new DateTime(2015, 12, 25)); // NYSE Closed on Christmas Day 2015
        SkipDates.Add(new DateTime(2016, 1, 1)); // NYSE Closed on New years day 2016
        SkipDates.Add(new DateTime(2016, 1, 15)); // NYSE Clsoed on Martin Luther King Day 2016
        SkipDates.Add(new DateTime(2016, 11, 24)); // NYSE Closed on Thanksgiving  2016
    }
}
/// <summary>
/// Example of how to make a Discontinuous DateTime Calender for the London Stock Exchange
///
/// If you wish to extend this, ensure that public holidays are set for the year(s) which you wish to show data
/// e.g. https://www.lseg.com/areas-expertise/our-markets/london-stock-exchange/equities-markets/trading-services/business-days
/// </summary>
public class LSECalendar : DiscontinuousDateTimeCalendarBase
{
    public LSECalendar()
    {
        // For intraday data, you can add a skip range like this.
        // For daily data, skip ranges will cause the Daily OHLC bars with timestamp at 0:00:00 to be skipped
        //SkipDayTimeRange.Add(new TimeSpanRange(new TimeSpan(0, 0, 0), new TimeSpan(8, 0, 0))); // LSE is open at 08:00am GMT
        //SkipDayTimeRange.Add(new TimeSpanRange(new TimeSpan(16, 30, 0), new TimeSpan(24, 0, 0))); // LSE is closed at 16:30pm GMT
        // LSE is closed on weekends
        SkipDaysInWeek.Add(DayOfWeek.Saturday);
        SkipDaysInWeek.Add(DayOfWeek.Sunday);
        SkipDates.Add(new DateTime(2015, 12, 25)); // LSE Closed on Christmas Day 2015
        SkipDates.Add(new DateTime(2016, 1, 1)); // LSE Closed on New Years day 2016
    }
}

DiscontinuousDateTimeAxis Usage

Data must be prepared for the DiscontinuousDateTimeAxis by applying a DiscontinuousFilter to DataSeries. It requires passing in the same Calendar that is used by the DiscontinuousDateTimeAxis to prepare data:

Preparing the data
Copy Code
using SciChart.Charting.Model.Filters;
// ...
void InitData()
{
    var calender = new LSECalendar();
    var priceData = new OhlcDataSeries<DateTime, double>
    priceData.Append(...); // Append some OHLC data to the series
   
    // Convert to a discontinuous series
    var priceDataDiscontinuous = (IOhlcDataSeries<DateTime, double>)_priceData.ToDiscontinuousSeries(calender);
   
    // Apply to the chart
    sciChartSurface.RenderableSeries.Add(new FastOhlcRenderableSeries { DataSeries = priceDataDiscontinuous });
}

Applying the DiscontinuousFilter filters out data points according to skip ranges in the Calendar and subscribes for subsequent changes of a DataSeries. Essentially it creates a new DataSeries internally that is compatible with the DiscontinuousDateTimeAxis.

NOTE:If a new Calendar is applied to a DiscontinuousDateTimeAxis, data must be updated accordingly by applying the DiscontinuousFilter with this Calendar to DataSeries.

Double-Scale DiscontinuousDateTimeAxis

This is a special kind of DiscontinuousDateTimeAxis that was designed to make axis scale of DiscontinuousDateTimeAxis to be more precise and clear. It introduces additional scale and allows to configure both scales via the LabelProvider API. Additionally, it allows shading of regular intervals on a chart based of axis scales. The shading interval is controlled via the AxisBandsFrequency property.

   

See Also